package org.example.myleet.p528;

import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        execute(new int[]{1,3});
        execute(new int[]{1});
        execute(new int[]{1,2,3,4,5});
    }

    private static void execute(int[] w) {
        int total = 100000;
        Map<Integer, Integer> countMap = new HashMap<>(10000);
        Solution solution1 = new Solution(w);
        for (int i = 0; i < total; ++i) {
            int idx = solution1.pickIndex();
            int count = countMap.getOrDefault(idx, 0);
            ++count;
            countMap.put(idx, count);
        }
        for (Map.Entry<Integer, Integer> entry : countMap.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue() / (double) total);
        }
        System.out.println("----------------");
    }
}
